<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          v-show="true"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="车辆入场时间">
          <a-date-picker :showTime="true" format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'carEnterTime', {}]"/>
        </a-form-item>
      </a-form>
    </a-spin>

  </a-modal>
</template>

<script>
import {httpAction} from '@/api/manage'
import pick from "lodash.pick";

export default {
  name: "ParkCarEnterLogModal",
  data() {
    return {
      title: "操作",
      visible: false,
      model: {},
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      url: {
        edit: "/parking/parkCarEnterLog/edit",
      },
    }
  },
  created() {
  },
  methods: {
    edit(record) {
      this.model = Object.assign({}, record);
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, 'carEnterTime'))
        this.confirmLoading = false
      });
      this.visible = true;
    },
    close() {
      this.$emit('close');
      this.visible = false;
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          httpurl += this.url.edit;
          method = 'put';
          let formData = Object.assign(this.model, values);
          //时间格式化
          formData.carEnterTime = formData.carEnterTime ? formData.carEnterTime.format('YYYY-MM-DD HH:mm:ss') : null;
          httpAction(httpurl, formData, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })
        }
      })
    },
    handleCancel() {
      this.close()
    },
  }
}
</script>


<style lang="less" scoped>

</style>
